<script setup lang="ts">
import { onMounted, onUnmounted, watch } from 'vue'
import { useAuthStore } from '@/stores/auth'
import { tboxSDKManager } from '@/utils/tboxSDK'

const authStore = useAuthStore()

// TBox SDK 配置
const TBOX_CONFIG = {
  agentId: '202511APY9A100562855'
}

onMounted(() => {
  // 只有在已登录时才初始化 TBox SDK
  if (authStore.isAuthenticated) {
    tboxSDKManager.init(TBOX_CONFIG, authStore.isAuthenticated)
  }
})

onUnmounted(() => {
  tboxSDKManager.destroy()
})

// 监听登录状态变化
watch(() => authStore.isAuthenticated, (isAuthenticated) => {
  if (isAuthenticated) {
    // 登录后初始化 TBox SDK
    tboxSDKManager.init(TBOX_CONFIG, isAuthenticated)
  } else {
    // 退出登录后销毁 TBox SDK
    tboxSDKManager.destroy()
  }
})
</script>

<template>
  <!-- TBox SDK 组件，不需要渲染任何内容 -->
</template>

